From cb129a0d441b4ea27ab96dc1d3e0e90d09c9ace3 Mon Sep 17 00:00:00 2001 From: robertl Date: Sun, 6 Apr 2003 19:34:56 +0000 Subject: [PATCH] Add airport, navaid, city, and landmarks to gpspilot. Courtesy Paul Tomblin. --- gpspilot.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/gpspilot.c b/gpspilot.c index 14b468079..267fea2b6 100644 --- a/gpspilot.c +++ b/gpspilot.c @@ -24,7 +24,11 @@ #include "coldsync/pdb.h" #define MYNAME "GPSPilot" -#define MYTYPE 0x706f696e /* poin */ +#define MYTYPE_POINTS 0x706f696e /* poin */ +#define MYTYPE_AIRPORT 0x706f3030 /* po00 */ +#define MYTYPE_CITIES 0x706f3031 /* po01 */ +#define MYTYPE_LNDMRKS 0x706f3032 /* po02 */ +#define MYTYPE_NAVAIDS 0x706f3033 /* po03 */ #define MYCREATOR 0x47704c69 /* GpLi */ struct record { @@ -34,6 +38,13 @@ struct record { pdb_16 magvar; /* magnetic variation in degrees, neg = west */ }; +struct runways { + pdb_32 be_longitude; /* Big endian, long * 3.6e6 */ + pdb_32 be_latitude; /* similarly */ + pdb_32 en_longitude; /* Big endian, long * 3.6e6 */ + pdb_32 en_latitude; /* similarly */ +}; + static FILE *file_in; static FILE *file_out; static const char *out_fname; @@ -97,7 +108,19 @@ data_read(void) fatal(MYNAME ": pdb_Read failed\n"); } - if ((pdb->creator != MYCREATOR) || (pdb->type != MYTYPE)) { + if ((pdb->creator != MYCREATOR)) { + fatal(MYNAME ": Not a gpspilot file.\n"); + } + + switch (pdb->type) + { + case MYTYPE_AIRPORT: + case MYTYPE_POINTS: + case MYTYPE_CITIES: + case MYTYPE_LNDMRKS: + case MYTYPE_NAVAIDS: + break; + default: fatal(MYNAME ": Not a gpspilot file.\n"); } @@ -110,10 +133,22 @@ data_read(void) rec = (struct record *) pdb_rec->data; wpt_tmp->position.longitude.degrees = be_read32(&rec->longitude) / 3.6e6; wpt_tmp->position.latitude.degrees = be_read32(&rec->latitude) / 3.6e6; - wpt_tmp->position.altitude.altitude_meters = be_read16(&rec->elevation) / 100.0; + wpt_tmp->position.altitude.altitude_meters = + be_read16(&rec->elevation); vdata = (char *) pdb_rec->data + sizeof(*rec); + /* + * skip runway records if an airport. + */ + if (pdb_rec->category == 0) + { + int numRunways; + numRunways = be_read16(vdata); + vdata += 2; + vdata += (sizeof(struct runways) * numRunways); + } + /* * This maping is a bit contrived. * Name is up to 36. ID is up to 9. @@ -208,7 +243,7 @@ data_write(void) opdb->name[PDB_DBNAMELEN-1] = 0; opdb->attributes = PDB_ATTR_BACKUP; opdb->ctime = opdb->mtime = time(NULL) + 2082844800U; - opdb->type = MYTYPE; + opdb->type = MYTYPE_POINTS; opdb->creator = MYCREATOR; opdb->version = 0; -- 2.30.2